package com.sosee.cgfw.friends;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;

import com.sosee.cgfw.R;
import com.sosee.cgfw.utils.Constans;
import com.sosee.cgfw.utils.Utils;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest;
import com.umeng.analytics.MobclickAgent;

/**
 * Created by Thinkpad on 2016/3/8.
 */
public class FriendsSetting extends Activity implements View.OnClickListener {
    private EditText friends_settingname;
    private TextView friends_settingButton;
    private ImageButton friends_back13;
    private String trim;
    private String id;
    private HttpUtils httpUtils;


    @Override
    protected void onResume() {
        super.onResume();
        MobclickAgent.onResume(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        MobclickAgent.onPause(this);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_friendsetting);
        Intent intent = getIntent();
        id = intent.getStringExtra("Id1");
        httpUtils = new HttpUtils();
        init();
    }

    private void init() {
        friends_settingname=(EditText)findViewById(R.id.friends_settingname);
        friends_settingButton=(TextView)findViewById(R.id.friends_settingButton);
        friends_back13= (ImageButton) findViewById(R.id.friends_back13);

        friends_back13.setOnClickListener(this);
        friends_settingButton.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.friends_back13:
                //关闭
                finish();
                break;

            case R.id.friends_settingButton:
                //提交备注。
                trim = friends_settingname.getText().toString().trim();
                if(trim.length()<2){
                    Utils.showToast("标注长度需大于2个字");
                    return;

                }
                //提交备注数据。
                request();

                break;
        }
    }

    private void request() {

        //14&friendsID=*&mark=*
        httpUtils.send(HttpRequest.HttpMethod.GET, Constans.SETINGNAME_URL+Constans.userID+"&friendsID="+id+"&mark="+trim, new RequestCallBack<String>() {

            @Override
            public void onSuccess(ResponseInfo<String> responseInfo) {

                String result = responseInfo.result;
                System.out.println("这是备注信息：" + result);
                Utils.showToast("设置成功");
                FriendsInfo.my_name11.setText(trim);
                finish();

            }

            @Override
            public void onFailure(HttpException e, String s) {
                Utils.showToast("设置失败，请检查网络");

            }
        });

    }
}
